﻿using RabbitMQ.Client;
using System.Text;

namespace DLXPublisher
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using var connection = factory.CreateConnection();
            using var channel = connection.CreateModel();

            channel.ExchangeDeclare(exchange: "dlx_task_exchange", type: "direct");
            channel.QueueDeclare(queue:"dlx_task_queue", durable: false, exclusive: false, autoDelete: false);
            channel.QueueBind(queue:"dlx_task_queue", exchange: "dlx_task_exchange", routingKey: "dlx_task_routingKey");

            channel.QueueDeclare(queue: "task_queue", durable: true, exclusive: false, autoDelete: false, arguments: new Dictionary<string, object>
            {
                { "x-dead-letter-exchange","dlx_task_exchange" },
                { "x-dead-letter-routing-key","dlx_task_routingKey" },
            });
            var message = "aaaa";

            var body = Encoding.UTF8.GetBytes(message);
            var properties = channel.CreateBasicProperties();
            properties.Persistent = true;
            //properties.DeliveryMode = 2;
            //properties.Expiration = "60000";
            channel.BasicPublish(exchange: string.Empty, routingKey: "task_queue", basicProperties: properties, body: body);
            Console.WriteLine($"[x] Sent {message}");

            Console.ReadLine();
        }
    }
}